package com.qk.service.impl;

import com.qk.mapper.BusinessMapper;
import com.qk.mapper.ClueMapper;
import com.qk.service.ReportService;
import com.qk.vo.OverviewVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @Override
    public OverviewVO getOverview() {
        //查看缓存数据
        Object object = redisTemplate.opsForValue().get("overview");//
        if (object != null){
            log.info("查询redis缓存中的数据: {}" , object);
            return (OverviewVO) object;
        }
        OverviewVO clueOverview = clueMapper.getClueOverview();
        OverviewVO businessOverview = businessMapper.getBusinessOverview();
        BeanUtils.copyProperties(clueOverview,businessOverview,"businessTotal", "businessWaitAllot", "businessWaitFollow", "businessFollowing", "businessFalse", "businessConvertCustomer");
        log.info("查询数据库中的数据: {}, 缓存到redis中", businessOverview);
        redisTemplate.opsForValue().set("overview",businessOverview,1, TimeUnit.MINUTES);
        return businessOverview;
    }
}
